package com.jxinternet.platform.services.repository.convert;

import com.jxinternet.platform.services.entity.cassandra.LogCassandra;
import com.jxinternet.platform.services.entity.domian.Log;
import com.jxinternet.platform.services.entity.mysql.LogMysql;
import org.springframework.stereotype.Service;

/**
 * Created by gold-jx on 2017/8/22.
 */
@Service
public class LogConvert implements BaseConvert<Log, LogMysql, LogCassandra> {

    @Override
    public LogMysql convertMysql(Log log) {
        if (log == null) {
            return null;
        }

        return copyEntityToMysql(log);
    }

    @Override
    public LogCassandra convertCassandra(Log log) {
        if (log == null) {
            return null;
        }
        return copyEntityToCassandra(log);
    }

    @Override
    public Log convertMysqlDomainToModel(LogMysql logMysql) {
        if (logMysql == null) {
            return null;
        }
        return copyMysqlToEntity(logMysql);
    }

    @Override
    public Log convertCassandraDomainToModel(LogCassandra logCassandra) {
        if (logCassandra == null) {
            return null;
        }
        return copyCassandraToEntity(logCassandra);
    }

    private static Log copyMysqlToEntity(LogMysql logMysql) {
        Log log = new Log();
        log.setId(logMysql.getId());
        log.setUserName(logMysql.getUserName());
        log.setLoginIp(logMysql.getLoginIp());
        log.setType(logMysql.getType());
        log.setOperation(logMysql.getOperation());
        log.setRemark(logMysql.getRemark());
        log.setState(logMysql.getState());
        log.setPlatformNo(logMysql.getPlatformNo());
        log.setCreateTime(logMysql.getCreateTime());
        log.setUpdateTime(logMysql.getUpdateTime());
        log.setVersion(logMysql.getVersion());
        return log;
    }

    private static Log copyCassandraToEntity(LogCassandra logCassandra) {
        Log log = new Log();
        log.setId(logCassandra.getId());
        log.setUserName(logCassandra.getUserName());
        log.setLoginIp(logCassandra.getLoginIp());
        log.setType(logCassandra.getType());
        log.setOperation(logCassandra.getOperation());
        log.setRemark(logCassandra.getRemark());
        log.setState(logCassandra.getState());
        log.setPlatformNo(logCassandra.getPlatformNo());
        //log.setCreateTime(logCassandra.getCreateTime());
        //log.setUpdateTime(logCassandra.getUpdateTime());
        //log.setVersion(logCassandra.getVersion());
        return log;
    }

    private static LogMysql copyEntityToMysql(Log log) {
        LogMysql logMysql = new LogMysql();
        logMysql.setId(log.getId());
        logMysql.setUserName(log.getUserName());
        logMysql.setLoginIp(log.getLoginIp());
        logMysql.setType(log.getType());
        logMysql.setOperation(log.getOperation());
        logMysql.setRemark(log.getRemark());
        logMysql.setState(log.getState());
        logMysql.setPlatformNo(log.getPlatformNo());
        logMysql.setCreateTime(log.getCreateTime());
        logMysql.setUpdateTime(log.getUpdateTime());
        logMysql.setVersion(log.getVersion());
        return logMysql;
    }

    private static LogCassandra copyEntityToCassandra(Log log) {
        LogCassandra logCassandra = new LogCassandra();
        logCassandra.setId(log.getId());
        logCassandra.setUserName(log.getUserName());
        logCassandra.setLoginIp(log.getLoginIp());
        logCassandra.setType(log.getType());
        logCassandra.setOperation(log.getOperation());
        logCassandra.setRemark(log.getRemark());
        logCassandra.setState(log.getState());
        logCassandra.setPlatformNo(log.getPlatformNo());
        //logCassandra.setCreateTime(log.getCreateTime());
        //logCassandra.setUpdateTime(log.getUpdateTime());
        //logCassandra.setVersion(log.getVersion());
        return logCassandra;
    }
}
